define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    // del_url: 'order/del',
                    multi_url: 'order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_number', title: __('Order_number')},
                        {field: 'product_id', title: __('Product_id')},
                        {field: 'user.name', title: __('User_id')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'order_price', title: __('Order_price'), operate:'BETWEEN'},
                        // {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'min_time', title: __('Min_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'after_price', title: __('After_price'), operate:'BETWEEN'},
                        // {field: 'after_min_time', title: __('After_min_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'number', title: __('Number')},
                        // {field: 'specs_id', title: __('Specs_id')},
                        // {field: 'qr_code', title: __('Qr_code')},
                        // {field: 'qr_number', title: __('Qr_number')},
                        {field: 'admission_time', title: __('Admission_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'appearance_time', title: __('Appearance_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'tk_number', title: __('Tk_number')},
                        {field: 'tk_order', title: __('Tk_order'), searchList: {"0":__('Tk_order 0'),"1":__('Tk_order 1'),"2":__('Tk_order 2')}, formatter: Table.api.formatter.normal},
                        {field: 'tk_price', title: __('Tk_price'), operate:'BETWEEN'},
                        {field: 'diff_time', title: __('Diff_time')},
                        {field: 'over_time', title: __('Over_time')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'refund_time', title: __('Refund_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});